﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Practices.Unity;

namespace MP3Ganizer.Modules.Visualisation.Views
{
    /// <summary>
    /// Interaction logic for VisualisationImageV.xaml
    /// </summary>
    public partial class VisualisationImageV : UserControl, IVisualisationImageV
    {
        #region Fields
        private readonly IUnityContainer _container;
        #endregion

        /// <summary>
        /// Constructeur.
        /// </summary>
        /// <param name="container"></param>
        public VisualisationImageV(IUnityContainer container)
        {
            this._container = container;
            InitializeComponent();
        }
        public VisualisationImageV()
        {
            InitializeComponent();
        }

        public void SetModel(ViewModels.IVisualisationVM model)
        {
            this.DataContext = model;
        }
        public void DisposeResources()
        {
            //ViewModels.IVisualisationVM model = this.DataContext as ViewModels.IVisualisationVM;
            //model.Path = "";
        }


        public void Show()
        {
            
            ViewModels.IVisualisationVM model = DataContext as ViewModels.IVisualisationVM;
            if (!System.IO.File.Exists(model.Path))
                return;

            try
            {
                BitmapImage bmp = new BitmapImage();
                System.IO.FileStream fs = new System.IO.FileStream(model.Path, System.IO.FileMode.Open);

                bmp.BeginInit();
                bmp.StreamSource = fs;
                bmp.CacheOption = BitmapCacheOption.OnLoad;
                bmp.EndInit();
                fs.Close();
                imgMain.Source = bmp;
                imgToolTip.Source = bmp;
            }
            catch
            {
                return;
            }
        }
    }
}
